{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">学费管理</li>
        </ul>
        <div class="layui-tab-content">

            <form id="form" class="layui-form layui-form-pane" action="{:url('admin/money/index')}" method="get">
                <div class="layui-inline">
                    <label class="layui-form-label">班级</label>
                    <div class="layui-input-inline">
                        <select name="class_id">
                            <option value="0">全部</option>
                            {foreach name="class_list" item="vo"}
                            {if condition="($vo.id == $class_id)"}
                            <option value="{$vo.id}" selected>{$vo.class_name}</option>
                            {else/}
                            <option value="{$vo.id}">{$vo.class_name}</option>
                            {/if}
                            {/foreach}
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">支付状态</label>
                    <div class="layui-input-inline">
                        <select name="status">
                            <option value="-1">全部</option>
                            <option value="0" {if condition="$status == 0"}selected{/if}>未支付</option>
                            <option value="1" {if condition="$status == 1"}selected{/if}>已支付</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" value="{$name}" placeholder="请输入姓名" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="phone" value="{$phone}" placeholder="请输入手机号" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">身份证</label>
                    <div class="layui-input-inline">
                        <input type="text" name="id_card" value="{$id_card}" placeholder="请输入身份证" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn">搜索</button>
                </div>
            </form>
            <hr>
            <form action="" method="post" class="ajax-form">
                <div class="layui-tab-item layui-show">
                    <table class="layui-table">
                        <thead>
                        <tr>
                            <th style="width: 10px;">ID</th>
                            <th style="width: 50px;">姓名</th>
                            <th style="width: 50px;">手机</th>
                            <th style="width: 50px;">身份证</th>
                            <th style="width: 50px;">班级</th>
                            <th style="width: 50px;">金额</th>
                            <th style="width: 50px;">状态</th>
                            <th style="width: 50px;">交费时间</th>
                            <th style="width: 100px;">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist  name="money_list" id="vo" empty="暂时没有数据"}
                        <tr>
                            <td>{$vo.id}</td>
                            <td>{$vo.name}</td>
                            <td>{$vo.phone}</td>
                            <td>{$vo.id_card}</td>
                            <td>{$vo.class_name}</td>
                            <td>{$vo.prac_amount}</td>
                            <td>
                                {if condition="$vo.status == 0"}
                                <span style="color: #FF5722;">未支付</span>
                                {/if}

                                {if condition="$vo.status == 1"}
                                <span style="color: #5FB878;">已支付</span>
                                {/if}
                            </td>
                            <td>
                                {if condition="mb_strlen($vo['update_time']) > 0"}
                                {$vo.update_time}
                                {else/}
                                --
                                {/if}
                            </td>
                            <td>
                                <a href="javascript:;" onclick="pay('{$vo.id}','{$vo.name}','{$vo.phone}','{$vo.id_card}')"
                                   class="layui-btn layui-btn-normal layui-btn-mini">交费</a>
                                <a href="javascript:;" onclick="print()"
                                   class="layui-btn layui-btn-warm layui-btn-mini">打印</a>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                    <!--分页-->
                    {$money_list->render()}
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    function pay(id, name, phone, id_card){
        layer.open({
            type: 1,
            skin: 'open-class',
            title:[name + '/' + phone + '/' + id_card, 'font-size:18px;'],
            area: ['500px', '200px'],
            content: '<input id="prac_amount" name="prac_amount" oninput="filterNumbers(this)" placeholder="请输入交费金额" value="" class="layui-input" />',
            btn: ['确定'],
            yes: function(index, layero){
                var prac_amount = $('#prac_amount').val();
                var data = {
                    'prac_amount' : prac_amount,
                    'id' : id
                };
                if (prac_amount > 0) {
                    $.post('{:url("pay")}', data, function(info) {
                        if (info.code === 1) {
                            setTimeout(function () {
                                location.href = info.url;
                            }, 1000);
                            layer.msg(info.msg);
                        } else {
                            layer.msg(info.msg, {icon: 5});
                        }
                    }, 'json');
                }
            },
        });
    }

    function filterNumbers(input) {
        input.value = input.value.replace(/[^\d.]/g, '');
    }

    function down_excel(){
        var formData = $("#form").serialize();
        var url = '{:url("excel")}' + "?" + formData;
        window.open(url, '_blank');
    }

    function print(){
        alert('暂未开发！');
    }

</script>
{/block}